
/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @author: jin Chen
 * @date: Jun 17, 2003
 * @version: $VERSION$
 */
package edu.psu.geovista.app.pcp.toolkits;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

public class SplitControl extends JPanel implements ComponentListener{

    protected JComponent left;
    protected JComponent right;
    protected JSplitPane splitPane;
    protected int dividerLocation=500;//location of divider to show left panel

    public SplitControl() {
    }

    public SplitControl(JComponent left, JComponent right) {
        this.left =left;
        this.right =right;
        this.setLayout(new BorderLayout());
        left.setMinimumSize(new Dimension(0,0));

        JScrollPane spLeft=new JScrollPane(left);
        JScrollPane spRight=new JScrollPane(right);
        splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,false,spLeft,spRight);

        splitPane.setOneTouchExpandable(true);
        splitPane.setDividerLocation(0);
        splitPane.setResizeWeight(0.0);
        //splitPane.setDividerLocation(0.0);
        //splitPane.setLastDividerLocation(0);
        this.add(splitPane);

        //this.add
        this.addComponentListener(this);
    }

    protected void setup(){
        JPanel control=new JPanel();
        JButton show=new JButton("Axis");
        show.addActionListener(new ActionListener(){
             boolean showed=false;
             int loc=400;
             public void actionPerformed(ActionEvent e){
                  //config.setActiveConfig(BasicConfig.AXIS_CONFIG );
                  this.show() ;

             }

             private void show(){
                 if (showed){
                    splitPane.setDividerLocation(0);
                    showed=false;
                 }
                 else{
                     splitPane.setDividerLocation(loc);
                     showed=true;
                 }
             }
        })  ;
        control.add(show);
        this.add(control,BorderLayout.WEST );
    }

    public int getDividerLocation() {
        return dividerLocation;
    }
    public void setDividerLocation(int location) {
        splitPane.setDividerLocation(location);
    }

    public JSplitPane getSplitPane() {
        return splitPane;
    }




    public void componentResized(ComponentEvent e) {
        JSplitPane sp = this.getSplitPane();
        int dloc = sp.getDividerLocation();

        //sp.setDividerLocation(0);
        //System.out.println("divider's location:"+dloc);
    }

    public void componentMoved(ComponentEvent e) {

    }

    public void componentShown(ComponentEvent e) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void componentHidden(ComponentEvent e) {

    }
}
